package com.edu.admin.controller;

import java.util.ArrayList;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.edu.admin.service.ClassesTeacherService;
import com.edu.admin.common.RestResult;


/**
 * 班级学科任课教师管理
 *  
 * @author Wangjiong
 * 
 */
@RestController
@RequestMapping(value = "/classesteacher", name = "班级学科任课教师管理")
public class ClassesTeacherController {
	
	@Autowired
	private ClassesTeacherService	classesTeacherService;
	
 
    /**
	 * 保存班级学科教师信息
	 *
	 * @apiGroup classesteacher
	 * @api {post} /classesteacher/save 保存班级学科教师信息
	 * @apiVersion 1.0.0
	 * @apiName save
	 *
	 * @apiParam {Map} dataMap 
	 * @apiParamExample 请求示例（json）
	 * {
		    "classesId": 2,
		    "subjectId": 4,
		    "teacherIds": [11,12,13]
		}
	 * 
	 * 
	 * @apiSuccessExample Success-Response:
	 * HTTP/1.1 200
		{
		    "code": 200,
		    "msg": "success",
		    "data": null
		}
	 *
	 *
	 */
	@RequestMapping(value = "save", name = "保存班级学科教师信息", method = RequestMethod.POST)
	@PreAuthorize("hasAuthority('/classesteacher/save')")
	public RestResult save(@RequestBody Map<String,Object> dataMap) throws Exception{
		
		Long classesId = MapUtils.getLong(dataMap, "classesId");
		Long subjectId = MapUtils.getLong(dataMap, "subjectId");
		@SuppressWarnings("unchecked")
		ArrayList<Integer> teacherIds = (ArrayList<Integer>)MapUtils.getObject(dataMap,"teacherIds");

    	Long[] ids = new Long[teacherIds.size()];
    		
	    for(int i=0;i<teacherIds.size();i++){

	    	ids[i] = teacherIds.get(i).longValue();

	    }
	    
	    classesTeacherService.saveClassesTeacher(classesId, subjectId, ids);
        
        return RestResult.ok();
	}
	
	

}
